package com.jfsoft.controller;

import org.jasig.cas.client.util.AbstractCasFilter;
import org.jasig.cas.client.validation.Assertion;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author ChenXc
 * @version V1.0
 * @Date 2018/3/16  16:08
 * @Description TODO(一句话描述类作用)
 */
@Controller
public class CasController {

    @RequestMapping(value = "/authentication", method = {RequestMethod.POST, RequestMethod.GET})
    public String login(HttpServletRequest request, HttpServletResponse response, Model model) {

        //是否为单点登录

        Object obj = request.getSession().getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
        if (obj != null) {
            Assertion assertion = (Assertion)obj;
            String userName = assertion.getPrincipal().getName();
//				User user = systemService.getUserByLoginName(userName);
            //获取用户信息进行session处理...
            return "redirect:" + "http://www.bjjfsoft.com";
        }

        return "login";
    }
}
